(function () {

	//获取维修合同细目其他数据 服务器分页
    var contractRepairOtherData = {};
    contractRepairOtherData.contractId=jQuery('#contractId').val();
    contractRepairOtherData.type="0";
    var serverRepairOtherTable;
    jQuery(document).ready(function () {
    	serverRepairOtherTable = jQuery('#resultRepairOtherTable').DataTable({
    		"serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/contract/getReplacement',
                "data": function (d) {
                    return $.extend({}, d, contractRepairOtherData);
                }
            },
            columns: [
                {
                	data: null
                },
                {
    	            data: null,
    	            defaultContent: "",
    	            render: function (data, type, full, meta) {
    	            	var id=data.id
    	            	var operate ='<input type="checkbox" class="checkchildRepairOther">';
    	            	return operate;
    	            }   
                },
                {
                    data: 'supplierCode'
                },
                {
                    data: 'deviceName'
                },
                {
                    data: 'type'
                },
                {
                	data: 'material'
                },
                {
                	data: 'unit'
                },
                {
                    data: 'amount'
                },
                {
                    data: 'price'
                }
                ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    	
    	//删除维修合同细目其他
    	jQuery('.delRepairOtherBtn').on('click', function () {
    		   var selects=getSelect("#resultRepairOtherTable",1);
    		   var url=window.rootPath+"/ui/contract/deleteReplacement";
    		   var contractId = jQuery("#contractId").val(); 
    		   var totalSum = jQuery("#totalSum").val();
    		   $("#checkAllRepairOther").prop("checked", false);
    		   delSelect(selects,url,serverRepairOtherTable);
    		   var urlxy = window.rootPath + '/ui/contract/checkMoney?contractId=' + contractId + '&totalSum=' + totalSum;
    		   jQuery.ajax({
               	type : 'get',
               	url : encodeURI(urlxy),
               	dataType : 'json',
               	contentType : 'application/json;charset=utf-8',
               	success : function(data) {
               		if(data==0){
               			alert("合同金额与细目的总金额相同！");
               		} else if(data==1){
               			alert("合同金额小于细目的总金额！");
               		} else if(data==2){
               			alert("合同金额大于细目的总金额！");
               		}
               	}
               });
    		});
    	
    	//维修合同细目新建弹窗显示
    	jQuery('.addRepairOtherBtn').on('click', function () {
    		var contractId = jQuery('#contractId').val();
        	if(contractId == ""){
            	if (confirm("当前合同还未保存，是否保存？")) {
            		saveContract('addRepairOtherBtn');
            	}
            }else{
            	showReplacementModal();
            }
    	});
    	
    	//维修合同细目编辑弹窗显示
    	jQuery('.editRepairOtherBtn').on('click', function () {
    		var selects=getSelect("#resultRepairOtherTable",1);
    		if(selects.length==0){
 		       $.springLemonDialog({
 		         content: '请选择需要编辑的记录',// 确认文本
 		         clickButton: function (sender, modal, index) {// 按钮事件处理
 		             $(this).closeDialog(modal);
 		         }
 		       }); 
 		    }else if(selects.length==1){
 		    	var replacementId=selects[0].id;
 		    	var replacementcreateTime=selects[0].createTime;
  			    var supplierCode=selects[0].supplierCode;
  			    var deviceName=selects[0].deviceName;
  			    var type=selects[0].type;
  			    var material=selects[0].material;
  			    var unit=selects[0].unit;
  			    var amount=selects[0].amount;
  			    var price=selects[0].price;
  			    jQuery('#replacementId').val(replacementId);
  			    jQuery("#replacementcreateTime").val(replacementcreateTime);
	  			jQuery('#oneSupplierCode1').val(supplierCode);
	  			jQuery('#deviceName').val(deviceName);
	  			jQuery('#type').val(type);
	  			jQuery('#material').val(material);
	  			jQuery('#unit').val(unit);
	  			jQuery('#amount').val(amount);
	  			jQuery('#price').val(price);
	  			jQuery('#moreSupplierCode1').val('');
	  			jQuery('#ids1').val('');
	  			jQuery("#selectContractId1").val('');
	  			document.getElementById("editOneReplacementAtrrForm").style.display='block';
	  			document.getElementById("editMoreReplacementAtrrForm").style.display='none';
  			    jQuery('#editReplacementModal').modal('show');
   		    }else{
 			   var ids=selects[0].id;
 			   for(var i=1;i<selects.length;i++){
 				   ids += ',' + selects[i].id;  
 			   }
 			   jQuery('#ids1').val(ids);
 			   jQuery('#replacementId').val('');
 			   jQuery("#replacementcreateTime").val('');
	  		   jQuery('#oneSupplierCode1').val('');
	  		   jQuery('#deviceName').val('');
	  		   jQuery('#type').val('');
	  		   jQuery('#material').val('');
	  		   jQuery('#unit').val('');
	  		   jQuery('#amount').val('');
	  		   jQuery('#price').val('');
	  		   jQuery('#moreSupplierCode1').val('');
	  		   jQuery("#selectContractId1").val('');
 			   document.getElementById("editMoreReplacementAtrrForm").style.display='block';
 			   document.getElementById("editOneReplacementAtrrForm").style.display='none';
 			   jQuery('#editReplacementModal').modal('show');
 		    }
    		
 		});
    	
    	//新建/编辑配件保存
    	jQuery('.saveReplacementBtn').on('click', function () {
    		$("#checkAllRepairOther").prop("checked", false);
    		//单个配件保存
    		if(jQuery("#editOneReplacementAtrrForm").css("display")=='block' && jQuery("#editMoreReplacementAtrrForm").css("display")=='none'){
    			if(jQuery("#editOneReplacementAtrrForm") && !jQuery("#editOneReplacementAtrrForm").Validform({tiptype:3, showAllError:true}).check(false)){
                    return;
                };
                jQuery(".saveReplacementBtn").attr("disabled", true);
                var totalSum = jQuery("#totalSum").val();
                var contractId = jQuery("#contractId").val();
    			var replacementId = jQuery('#replacementId').val();
    			var createTime = jQuery("#replacementcreateTime").val();
    			var contractID = jQuery("#contractId").val();
    			var contractType = "维修合同";
      			var deviceName = jQuery('#deviceName').val();
      			var type = jQuery('#type').val();
      			var material = jQuery('#material').val();
      			var unit = jQuery('#unit').val();
      			var amount = jQuery('#amount').val();
      			var price = jQuery('#price').val();
      			var selectContractId = jQuery("#selectContractId1").val();
      			var oneSupplierCode = jQuery("#oneSupplierCode1").val();
      			//暂时将选择关联的项目合同ID与合同号存在数据的supplierCode中，方便使用；
      			if (replacementId == '') {
	      			var data={
	      					"contractID":contractID,
	                        "contractType":contractType,
	                        "supplierCode":selectContractId+":"+oneSupplierCode,
	                        "deviceName": deviceName,
	                        "type": type,
	                        "material": material,
	                        "unit": unit,
	                        "amount": amount,
	                        "price": price
	                    };
      			} else{
	      			var data={
	                        "id":replacementId,
	                        "createTime" : createTime,
	                        "contractID":contractID,
	                        "contractType":contractType,
	                        "supplierCode":selectContractId+":"+oneSupplierCode,
	                        "deviceName": deviceName,
	                        "type": type,
	                        "material": material,
	                        "unit": unit,
	                        "amount": amount,
	                        "price": price
	                    };
      			}
                    var url=window.rootPath+'/ui/contract/editOneReplacement';
                    var urlxy = window.rootPath + '/ui/contract/checkMoney?contractId=' + contractId + '&totalSum=' + totalSum;
                    jQuery.ajax({
                        url:encodeURI(url),
                        type:'post',
                        data:JSON.stringify(data),
                        dataType:'json',
                        contentType:'application/json;charset=utf-8',
                        success: function () {
                            jQuery('#editReplacementModal').modal('hide');
                            contractRepairOtherData.contractId=jQuery('#contractId').val();
                            serverRepairOtherTable.draw(false);
                            jQuery(".saveReplacementBtn").attr("disabled", false);
                            jQuery.ajax({
        						type : 'get',
        						url : encodeURI(urlxy),
        						dataType : 'json',
        						contentType : 'application/json;charset=utf-8',
        						success : function(data) {
        							if(data==0){
        								alert("合同金额与细目的总金额相同！");
        							} else if(data==1){
        								alert("合同金额小于细目的总金额！");
        							} else if(data==2){
        								alert("合同金额大于细目的总金额！");
        							}
        						}
        					});
                        }

                    });
    		}
    		//多个配件保存
    		else if(jQuery("#editOneReplacementAtrrForm").css("display")=='none' && jQuery("#editMoreReplacementAtrrForm").css("display")=='block'){
    			if(jQuery("#editMoreReplacementAtrrForm") && !jQuery("#editMoreReplacementAtrrForm").Validform({tiptype:3, showAllError:true}).check(false)){
                    return;
                };
                jQuery(".saveReplacementBtn").attr("disabled", true);
                var totalSum = jQuery("#totalSum").val();
                var contractId = jQuery("#contractId").val();
                var ids = jQuery('#ids1').val();
                var selectContractId = jQuery("#selectContractId1").val();
                var url=window.rootPath+"/ui/contract/editMoreReplacement"+"?replacementInfo="+ ids +":"+ selectContractId;
                var urlxy = window.rootPath + '/ui/contract/checkMoney?contractId=' + contractId + '&totalSum=' + totalSum;
                jQuery.ajax({
                    url:encodeURI(url),
                    cache:false,
                    type : "get",
                    dataType:"json",
                    success:function(data){
                    	jQuery('#editReplacementModal').modal('hide');
                    	contractRepairOtherData.contractId=jQuery('#contractId').val();
                    	serverRepairOtherTable.draw(false);
                    	jQuery(".saveReplacementBtn").attr("disabled", false);
                    	jQuery.ajax({
    						type : 'get',
    						url : encodeURI(urlxy),
    						dataType : 'json',
    						contentType : 'application/json;charset=utf-8',
    						success : function(data) {
    							if(data==0){
    								alert("合同金额与细目的总金额相同！");
    							} else if(data==1){
    								alert("合同金额小于细目的总金额！");
    							} else if(data==2){
    								alert("合同金额大于细目的总金额！");
    							}
    						}
    					});
                    }
                });
    		}
    	});
    	
    	//EXCEL导入
        jQuery('.importRepairOtherList').on("click",function()
        {
        	var contractId = jQuery('#contractId').val();
        	var type = '2';
        	if(contractId == ""){
            	if (confirm("当前合同还未保存，是否保存？")) {
            		saveContract("importRepairOtherList");
            	}
            }else{
            	fileUpload(contractId, type);
            }
        });
        
        /**
    	 * 保存维修合同
    	 */
        var saveContract = function(state) {
        	var signedDate = jQuery('#signedDate').val();
        	var giveOutDate = jQuery('#giveOutDate').val();
        	var scheduleDate = jQuery('#scheduleDate').val();
         	var repairDate = jQuery('#repairDate').val();
     		var operatDate = jQuery('#operatDate').val();
     		if (signedDate==""||giveOutDate==""||repairDate==""||operatDate==""){
     			message("请将页面上所有日期信息完善，保存后还可进行编辑。");
     			return ;
     		}
     		var isId=jQuery("#contractId").val();
     		var contractcreateTime=jQuery("#createTime").val();
      	    var createTime=new Date(contractcreateTime).getTime();
            var supplierCode = jQuery('#supplierCode').val();
        	var demanderCode = jQuery('#demanderCode').val();
        	var contractType = jQuery('#contractType').val();
     		var totalSum = jQuery('#totalSum').val();
     		var repairCode = jQuery('#repairCode').val();
 			var repairNumber = jQuery('#repairNumber').val();
 			var repairKind = jQuery('#repairKind').val();
     		var projectCode = jQuery('#projectCode').val();
     		var stop = jQuery('#stop').val();
     		var freightCharge = jQuery('#freightCharge').val();
     		var projectName = jQuery('#projectName').val();
         	var payType = jQuery('#payType').val();
         	var guaranteePeriod = jQuery('#guaranteePeriod').val();
         	var breakDuty = jQuery('#breakDuty').val();
         	var customerId = jQuery("#customerId").val();
     		var orderUnit = jQuery('#orderUnit').val();
         	var orderDelegate = jQuery('#orderDelegate').val();
     		var orderPhone = jQuery('#orderPhone').val();
     		var industryInfo = jQuery('#industryInfo').val();
     		var orderAddress = jQuery('#orderAddress').val();
     		var orderZip = jQuery('#orderZip').val();
     		var orderArea = jQuery('#orderArea').val();
     		var invoiceBank = jQuery("#invoiceBank").val();
      		var bankAccount = jQuery("#bankAccount").val();
      		var taxNumber = jQuery("#taxNumber").val();
      		var invoiceAddress = jQuery("#invoiceAddress").val();
     		var postUnit = jQuery('#postUnit').val();
         	var postDelegate = jQuery('#postDelegate').val();
     		var postPhone = jQuery('#postPhone').val();
     		var postAddress = jQuery('#postAddress').val();
     		var postZip = jQuery('#postZip').val();
     		var dutyArea = jQuery('#dutyArea').val();
     		var dutyOfficer = jQuery('#dutyOfficer').val();
     		var southNorthArea = jQuery('#southNorthArea').val();
     		var belongArea = jQuery('#belongArea').val();
     		var checkKind = jQuery('#checkKind').val();
     		var productKind = jQuery('#productKind').val();
     		var signOfficer = jQuery('#signOfficer').val();
     		var repairOfficer = jQuery('#repairOfficer').val();
     		var quotationOfficer = jQuery('#quotationOfficer').val();
     		var operatDepartment = jQuery('#operatDepartment').val();
     		var operator = jQuery('#operator').val();
     		var memo = jQuery('#memo').val();
     		var state = jQuery('#state').val();
     		var cstate = jQuery('#cstate').val();
     		if(isId == ""){// 新增合同
     			var d = {
         				"user":{"id":$("#userId").val()},
                    	"supplierCode": supplierCode,
                    	"demanderCode": demanderCode,
                    	"contractType": contractType,
                        "totalSum": totalSum,
                        "signedDate": signedDate,
                        "scheduleDate": scheduleDate,
                        "giveOutDate": giveOutDate,
                        "repairCode": repairCode,
                        "repairNumber": repairNumber,
                        "repairKind": repairKind,
                        "repairDate": repairDate,
                        "projectCode": projectCode,
                        "stop": stop,
                        "freightCharge": freightCharge,
                        "projectName": projectName,
                        "payType": payType,
                        "guaranteePeriod": guaranteePeriod,
                        "breakDuty": breakDuty,
                        "customerId": customerId,
                        "orderUnit": orderUnit,
                        "orderDelegate": orderDelegate,
                        "orderPhone": orderPhone,
                        "industryInfo": industryInfo,
                        "orderAddress": orderAddress,
                        "orderZip": orderZip,
                        "orderArea": orderArea,
                        "invoiceBank": invoiceBank,
      	                "bankAccount": bankAccount,
      	                "taxNumber": taxNumber,
      	                "invoiceAddress": invoiceAddress,
                        "postUnit": postUnit,
                        "postDelegate": postDelegate,
                        "postPhone": postPhone,
                        "postAddress": postAddress,
                        "postZip": postZip,
                        "dutyArea": dutyArea,
                        "dutyOfficer": dutyOfficer,
                        "southNorthArea": southNorthArea,
                        "belongArea": belongArea,
                        "checkKind": checkKind,
                        "productKind": productKind,
                        "signOfficer": signOfficer,
                        "repairOfficer": repairOfficer,
                        "quotationOfficer": quotationOfficer,
                        "operatDepartment": operatDepartment,
                        "operator": operator,
                        "operatDate": operatDate,
                        "memo": memo,
                        "state": state,
                        "cstate": cstate,
                };
     		}else{
     			var d = {
     					"id": isId,
  	        			"createTime": createTime,
                    	"supplierCode": supplierCode,
                    	"demanderCode": demanderCode,
                    	"contractType": contractType,
                        "totalSum": totalSum,
                        "signedDate": signedDate,
                        "scheduleDate": scheduleDate,
                        "giveOutDate": giveOutDate,
                        "repairCode": repairCode,
                        "repairNumber": repairNumber,
                        "repairKind": repairKind,
                        "repairDate": repairDate,
                        "projectCode": projectCode,
                        "stop": stop,
                        "freightCharge": freightCharge,
                        "projectName": projectName,
                        "payType": payType,
                        "guaranteePeriod": guaranteePeriod,
                        "breakDuty": breakDuty,
                        "customerId": customerId,
                        "orderUnit": orderUnit,
                        "orderDelegate": orderDelegate,
                        "orderPhone": orderPhone,
                        "industryInfo": industryInfo,
                        "orderAddress": orderAddress,
                        "orderZip": orderZip,
                        "orderArea": orderArea,
                        "invoiceBank": invoiceBank,
      	                "bankAccount": bankAccount,
      	                "taxNumber": taxNumber,
      	                "invoiceAddress": invoiceAddress,
                        "postUnit": postUnit,
                        "postDelegate": postDelegate,
                        "postPhone": postPhone,
                        "postAddress": postAddress,
                        "postZip": postZip,
                        "dutyArea": dutyArea,
                        "dutyOfficer": dutyOfficer,
                        "southNorthArea": southNorthArea,
                        "belongArea": belongArea,
                        "checkKind": checkKind,
                        "productKind": productKind,
                        "signOfficer": signOfficer,
                        "repairOfficer": repairOfficer,
                        "quotationOfficer": quotationOfficer,
                        "operatDepartment": operatDepartment,
                        "operator": operator,
                        "operatDate": operatDate,
                        "memo": memo,
                        "state": state,
                        "cstate": cstate,
                };
     		}
     		jQuery(".addRepairPumpBtn").attr("disabled", true);
      		jQuery(".importRepairPumpList").attr("disabled", true);
      		jQuery(".addRepairOtherBtn").attr("disabled", true);
      		jQuery(".importRepairOtherList").attr("disabled", true);
      		var id=isId;
      		if (id==null||id==''){
      			id = 'null';
      		}
      		if (cstate=="已完成"){
      			$.springLemonDialog({
  					content : '该合同已经生产商品计划，不能保存！',// 确认文本
  					clickButton : function(sender, modal, index) {// 按钮事件处理
  						$(this).closeDialog(modal);
  					}
      			});
  			}
      		if(cstate=="已排产"){
      			alert("保存合同后将修改排产相关信息。");
      		}
      		if (supplierCode!=''){// 验证供方合同号是否已存在
      			var urlValid=window.rootPath+"/ui/contract/validSupplierCode/"+id+"/"+supplierCode;
      	    	jQuery.ajax({
      	            url:encodeURI(urlValid),
      	            cache:false,
      	            type :"get",
      	            dataType:"json",
      	            contentType:"application/json;charset=utf-8",// 解决返回数据中的中文乱码问题
      	            success:function(data){
      	            	if(data.codeState==1){
      	            		$.springLemonDialog({
      		      		         content: '供方合同号已存在，请修改！',// 确认文本
      		      		         clickButton: function (sender, modal, index) {// 按钮事件处理
      		      		             $(this).closeDialog(modal);
      		      		         }
      		            		});
      	            		jQuery(".addRepairPumpBtn").attr("disabled", false);
      	            		jQuery(".importRepairPumpList").attr("disabled", false);
      	            		jQuery(".addRepairOtherBtn").attr("disabled", false);
      	            		jQuery(".importRepairOtherList").attr("disabled", false);
      	            		return;
      	            	}
      	                    var url = window.rootPath + "/ui/contract/saveContractRepair";
      	                    jQuery.ajax({
      	                        type: 'post',
      	                        url: url,
      	                        data: JSON.stringify(d),
      	                        dataType: 'json',
      	                        contentType: 'application/json;charset=utf-8',
      	                        success: function (data) {
      	                        	var contractId = data.contractId;
      	                        	var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss")
      	                        	jQuery("#createTime").val(time);
      	                        	jQuery("#contractId").val(contractId);
      	                        	jQuery(".addRepairPumpBtn").attr("disabled", false);
      	                    		jQuery(".importRepairPumpList").attr("disabled", false);
      	                    		jQuery(".addRepairOtherBtn").attr("disabled", false);
      	                    		jQuery(".importRepairOtherList").attr("disabled", false);
      	                        	if (state=="addRepairOtherBtn"){
      	                        		showReplacementModal();
      	                        	}else if(state=="importRepairOtherList"){
      	                        		var type = '2';
      	                        		fileUpload(contractId, type);
      	                        	}
      	                        }
      	                    });
      	            }
      	    	});
      		}else{
      	            var url = window.rootPath + "/ui/contract/saveContractRepair";
      	            jQuery.ajax({
      	                type: 'post',
      	                url: url,
      	                data: JSON.stringify(d),
      	                dataType: 'json',
      	                contentType: 'application/json;charset=utf-8',
      	                success: function (data) {
      	                	var contractId = data.contractId;
      	                	var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss")
	                        jQuery("#createTime").val(time);
      	                	jQuery("#contractId").val(contractId);
      	                	jQuery(".addRepairPumpBtn").attr("disabled", false);
      	            		jQuery(".importRepairPumpList").attr("disabled", false);
      	            		jQuery(".addRepairOtherBtn").attr("disabled", false);
      	            		jQuery(".importRepairOtherList").attr("disabled", false);
	                        if (state=="addRepairOtherBtn"){
	                        	showReplacementModal();
	                       	}else if(state=="importRepairOtherList"){
  	                        	var type = '2';
  	                       		fileUpload(contractId, type);
  	                       	}
      	                }
      	            });
      		}
        }
        
        /**
    	 * 添加其他时初始化弹窗
    	 */
        var showReplacementModal = function() {
        	jQuery('#replacementId').val('');
        	jQuery("#replacementcreateTime").val('');
    		jQuery('#oneSupplierCode1').val('');
    		jQuery('#deviceName').val('');
    		jQuery('#type').val('');
    		jQuery('#material').val('');
    		jQuery('#unit').val('');
   			jQuery('#amount').val('');
   			jQuery('#price').val('');
  			jQuery('#moreSupplierCode1').val('');
    		jQuery('#ids1').val('');
    		jQuery("#selectContractId1").val('');
    		document.getElementById("editOneReplacementAtrrForm").style.display='block';
    		document.getElementById("editMoreReplacementAtrrForm").style.display='none';
    		jQuery('#editReplacementModal').modal('show');
        }
    	
    	/**
    	 * 文件上传插件
    	 */
    	var fileUpload = function(contractId, type) {
    		var root = window.rootPath;
    		WebFilesUploader(
    				{
    					_webuploader : {
    						server : root + '/ui/contract/import/' + contractId +'/'+ type,
    						swf : root
    								+ '/resources/poweradminjs/webupload/webfilesuploader/Uploader.swf',
    						chunked:false		
    					}
    				
    				}, function(jsons) {  				
    					serverRepairOtherTable.draw(true);
    				});
           
    	
    	};
    	
        //细目其他关联合同弹窗中合同信息table,
       	//(维修合同细目其他为避免冲突使用单独的js,重复的字段后加“1”用于区分,
       	// 备件合同细目备件、备泵合同细目备泵以及维修合同细目泵的新建/编辑弹窗都使用contractindex.js)
        	  var serverContractData1={};
        	  var serverContractTable1;
        	  jQuery(document).ready(function () {

        		serverContractTable1 = jQuery('#resultContractTable1').DataTable({
        	            "serverSide": true,
        	            "ordering": false,
        	            "iDisplayLength": 5,
        	            "ajax": {
        	                "dataType": "json",
        	                "type": "get",
        	                "cache": false,
        	                "url":window.rootPath+ '/ui/contract/getContract',
        	                "data": function (d) {
        	                    return $.extend({}, d, serverContractData1);
        	                }
        	            },
        	            columns: [
        	                {
        	                	data: null
        	                },
        	                {
        	                	data : null,
        						defaultContent : "",
        						render : function(data,type, full, meta) {
        							var operate = '<button type="button" class="btn btn-info btn-sm selectBtn">选择</button>';
        							return operate;
        						}  
        	                },
        	                {
        	                    data: 'supplierCode'
        	                },
        	                {
        	                    data: 'belongArea'
        	                },
        	                {
        	                    data: 'totalSum'
        	                },
        	                {
      	                    data: 'signedDate',
      	                    render: function (data, type, full, meta) {
      	                        if (data)
      	                            return moment(data).format('YYYY/MM/DD');
      	                        else
      	                            return '';
      	                    }
        	                },
        	                {
        	                    data: 'projectName'
        	                },
        	                {
        	                    data: 'orderUnit'
        	                },
        	                {
        	                    data: 'orderArea'
        	                }
        	                ],
        	            "drawCallback": function (oSettings) {
        	                var k = 0;
        	                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

        	                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
        	                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
        	                    k++;
        	                }
        	                    serverContractTable1.off('click', 'tr');
        	                    serverContractTable1.on('click','tr',function(event) {
        					    event = event|| window.event;
        						var target = event.target|| event.scrElement;
        						var data = serverContractTable1.row(this).data();
        						if (target.className.indexOf('selectBtn') != -1) {
        							selectContract(data);
        						}
        					return;
        					});
        	            }
        	        });
        		   //选择合同
        		   var  selectContract=function(data){
        			    jQuery("#selectContractId1").val(data.id);
    					jQuery("#oneSupplierCode1").val(data.supplierCode);
    					jQuery("#moreSupplierCode1").val(data.supplierCode);
        		   }
        	  });
        	  
        	//查询关联的合同
            jQuery('.searchContractBtn1').on('click',function(){
                serverContractData1.key=jQuery('#keywordContract1').val();
                serverContractTable1.draw();
            })
            //撤销查询关联的合同
            jQuery('.resetContractBtn1').on("click",function()
            {
                jQuery('#keywordContract1').val('');
                serverContractData1.key ='';
                serverContractTable1.draw();
            });
    	
    	//列表中的全选
        $("#checkAllRepairOther").click(function(){
        	var check = $(this).prop("checked");
            $(".checkchildRepairOther").prop("checked", check);
    	});
    	
    });
})();